PermissionTexts: Custom the Permission Texts for Dialogs and Drawers
The permissionTexts
module provides many interfaces for applications to manage the permission texts for dialogs and drawers.
Developers can determine whether these interfaces work in the EdgerOS mobile App environment through the following code:
edger.env().then(data => {
if (data.env === 'edgerapp') {
// We work in EdgerOS mobile App environment.
}
}).catch(error => {
console.error(error);
});
You need to use canIUse
API to determine whether the API can be used.
const canIUse = edger.canIUse({
name: 'permissionTexts.register'
})
if (canIUse) {
// Here you can use `edger.permissionTexts.register`
}
Functions
edger.permissionTexts.register(params)
Register permission texts for the current EAP.
params
{Array<PermissionText>} The array of thePermissionText
.- Returns: {Promise<{success: boolean}>} Promise object.
The params
is an array of the PermissionText
. Each PermissionText
item contains the following members:
type
{String} Consistent with the type inedger.permission.request(option)
API. Permission types:permissions
|devices
|phone
|vehicle
. Currently, thevehicle
type is not supported.code
{String} Consistent with the type inedger.permission.request(option)
API.dialogContent
{string} Permission dialog content. This parameter can modify the permission content of dialog, such as the permission dialog triggered byedger.fs.showMediaSelector(options)
. Optional.drawerContent
{string} Permission drawer content. This parameter can modify the permission content ofedger.permission.request(option)
API. Theedger.permissionTexts.register(options)
API must be called beforeedger.permission.request(option)
API. Optional.
The corresponding table of permission request types and code is as follows:
type | code |
---|---|
permissions | ainn , alarm , share , notify , advnwc , network , display , rtsp , lora , coap , wallpaper , account , printer , auxstorage , vpn , mqtt.publish , mqtt.subscribe , mediacenter.readable , mediacenter.writable , mediacenter.removable |
devices | List of allowed device IDs |
phone | camera , microphone , geolocation , browser , media , file , contacts |
vehicle | media , geolocation , diagnostic , cockpit , drive |
Example
edger.permissionTexts.register([{
type: 'phone',
code: 'media',
dialogContent: '请前往手机设置为爱智 App 开启“相册”权限',
drawerContent: '请前往手机设置为爱智 App 开启“相册”权限'
}]).then((data) => {
console.log(data.success)
})
async / await
try {
const { success } = await edger.permissionTexts.register([{
type: 'phone',
code: 'media',
dialogContent: '请前往手机设置为爱智 App 开启“相册”权限',
drawerContent: '请前往手机设置为爱智 App 开启“相册”权限'
}])
console.log(success)
} catch (error) {
console.error(error);
}
edger.permissionTexts.unregister(params)
Unregister permission texts for the current EAP.
params
{Array<UnregisterParam>} The array of theUnregisterParam
.- Returns: {Promise<{success: boolean}>} Promise object.
The params
is array of the UnregisterParam
. If this params
is empty, it means unregister all permission texts. Optional.
Each Param
item contains the following members:
type
{String} Permission type.code
{String} Permission code.
Example
edger.permissionTexts.unregister([{
type: 'phone',
code: 'media'
}]).then(data => {
console.log(data.success)
})
async / await
try {
const { success } = await edger.permissionTexts.unregister([{
type: 'phone',
code: 'media'
}]);
console.log(success)
} catch (error) {
console.error(error);
}
edger.permissionTexts.query()
Query registrarion texts for the current EAP.
- Returns: {Promise< { result: Array<PermissionText> } >}.
Example
edger.permissionTexts.query().then(data => {
console.log(data.result)
})
async / await
try {
const { result } = await edger.permissionTexts.query();
// eg:
// result = [{
// type: 'phone',
// code: 'media',
// dialogContent: '请前往手机设置为爱智 App 开启“相册”权限',
// drawerContent: '请前往手机设置为爱智 App 开启“相册”权限'
// }]
console.log(result)
} catch (error) {
console.error(error);
}